

<script language='javascript'>
    var winForm;
    $(document).ready(function() {

        function deleteItem(record){
            Rocket.Request({
                url: BASE_URL + 'tiporols/del',
                data:record.definition,
                success:function(data) {
                    if (data.success){
                        grid.load();
                    }
                    else{
                        Rocket.Create({
                            type:'dialog',
                            title:'Error en la operacion',
                            typeAlert:'error',
                            message:_getErrorFromArray(data.errors)
                        });
                    }
                }
            });
        }
        
        function showForm(record,type){
            var title = 'Crear Tiporols';
            if(type === 'edit'){
                title = 'Editar Tiporols';
            }
            if(!winForm){
                winForm = Rocket.Create({
                    type:'panel',
                    id:'winForm',
                    title:title,
                    width:'50%',
                    collapsible:true,
                    modal:true,
                    isForm:true,
                    autoLoad:false,
                    proxy:{
                        url: BASE_URL+'tiporols/'+type
                    },
                    items: [
                        {
                            type: 'hidden',
                            name: '_TipoRolId',
                            id:'rck_hidden_TipoRolId'
                        },
                        {
                            type: 'text',
                            label: 'nombre',
                            name: 'nombre',
                            id:'rck_nombre'
                        },
                        {
                            type: 'text',
                            label: 'nombrerol',
                            name: 'nombrerol',
                            id:'rck_nombrerol'
                        },
                        {
                            type: 'text',
                            label: 'descripcion',
                            name: 'descripcion',
                            id:'rck_descripcion'
                        },
                        {
                            type: 'hidden',
                            label: 'Log',
                            name: 'Log',
                            id:'rck_Log'
                        }],
                    buttons:[
                        {
                            type:'button',
                            id:'btnSubmit',
                            name:'submit',
                            value:'Guardar',
                            handler:function(){
                                var values = winForm.getValues();
                                winForm.submit({
                                    data:values,
                                    success:function(data){
                                        if(data.success){
                                            winForm.resetForm();
                                            Rocket.Create({
                                                type:'dialog',
                                                title:'Operaci\u00F3n exitosa',
                                                typeAlert:'success',
                                                message:data.msg
                                            });
                                            grid.load();
                                            winForm.close();
                                        }
                                        else{
                                            Rocket.Create({
                                                type:'dialog',
                                                title:'Error en la operacion',
                                                typeAlert:'error',
                                                message:_getErrorFromArray(data.errors)
                                            });
                                        }
                                    }
                                });
                            }
                        },
                        {
                            type:'button',
                            id:'btnCancel',
                            name:'cancel',
                            value:'Cancelar',
                            handler:function(){
                                winForm.resetForm();
                                winForm.close();
                            }
                        }
                    ]
                });
            }
            else{
                winForm.setTitleDialog(title);
            }
            if(type==='edit'){
                var get = {item:Rocket.encode(record.definition)}
                winForm.fill({
                    proxy:{url:BASE_URL+'tiporols/getItem'},
                    data:get,
                    success:function(data){
                        winForm.proxy.url = BASE_URL+'tiporols/edit';
                        winForm.show();
                    }
                });
            }
            else{
                winForm.proxy.url = BASE_URL+'tiporols/add';
                winForm.show();
            }
          
        }
        
        grid = Rocket.Create({
            type:'grid',
            id: 'gridTiporols',
            width:'100%',
            height:400,
            title:'Tiporols',
            collapsible:true,
            autoLoad:true,
            fit:true,
            renderTo:'divTiporols',
            proxy:{
                url:BASE_URL+'tiporols/loadGrid'
            },
            toolbar:[
                {
                    type:'button',
                    id:'addtiporols',
                    value:'Agregar',
                    iconCls:'rck-icon-add',
                    handler:function(){
                        showForm(null,'add');
                    }
                }
            ],
            columns: [{display: 'TipoRolId',name: 'TipoRolId', width:'10',sortable:true},{display: 'nombre',name: 'nombre', width:'10',sortable:true},{display: 'nombrerol',name: 'nombrerol', width:'10',sortable:true},{display: 'descripcion',name: 'descripcion', width:'10',sortable:true},{display: 'Log',name: 'Log', width:'10',sortable:true},
                {
                    display:'Acciones',
                    name:'Acciones',
                    width:'40',
                    align:'center',
                    type:'action',
                    items:[
                        {
                            title:'Editar',
                            iconCls:'rck-icon-edit',
                            handler:function(record){
                                showForm(record,'edit');
                            }
                        },
                        {
                            title:'Eliminar',
                            iconCls:'rck-icon-del',
                            handler:function(record){
                                var model = record;
                                Rocket.Create({
                                    type:'dialog',
                                    title:'Confirme la operacion',
                                    typeAlert:'confirmation',
                                    message:'Esta seguro que desea eliminar el registro seleccionado?',
                                    onOkHanlder:function(){
                                        deleteItem(model);
                                    }
                                });
                            }
                        }
                    ]
                }
            ]
            ,
            searchitems : [
                {display: 'TipoRolId',name: 'TipoRolId', width:'10',sortable:true},{display: 'nombre',name: 'nombre', width:'10',sortable:true},{display: 'nombrerol',name: 'nombrerol', width:'10',sortable:true},{display: 'descripcion',name: 'descripcion', width:'10',sortable:true},{display: 'Log',name: 'Log', width:'10',sortable:true}
            ]
        });
    });
</script>
<?php echo utf8_decode($module_banner);?>
<ul class='ul_page'>
    <li><div id='divTiporols'></div></li>
</ul>
